#########################################################################
##
## This file is part of the SAMRAI distribution.  For full copyright 
## information, see COPYRIGHT and LICENSE. 
##
## Copyright:     (c) 1997-2019 Lawrence Livermore National Security, LLC
## Description:   makefile for nonlinear solver test 
##
#########################################################################

SAMRAI        = @top_srcdir@
SRCDIR        = @srcdir@
SUBDIR        = source/test/nonlinear
VPATH         = @srcdir@
TESTTOOLS     = ../testtools
OBJECT        = ../../..
REPORT        = $(OBJECT)/report.xml

default: check	

include $(OBJECT)/config/Makefile.config

SUBDIRS = fortran

CPPFLAGS_EXTRA= -DDISPLAY -DTESTING=1

NUM_TESTS = 2

TEST_NPROCS = @TEST_NPROCS@
QUOTE = \"

CXX_OBJS      = main.o ModifiedBratuProblem.o
F_OBJS      =	\
	fortran/FACjacobian1d.o \
	fortran/bcFluxCopy1d.o \
	fortran/bcFluxFix1d.o \
	fortran/bratufunc1d.o \
	fortran/err1d.o \
	fortran/evalBratu1d.o \
	fortran/evalDiffusionCoef1d.o \
	fortran/evalExponential1d.o \
	fortran/evalF1d.o \
	fortran/evalFaceFluxes1d.o \
	fortran/evalJv1d.o \
	fortran/evalSource1d.o \
	fortran/setbc1d.o \
	fortran/adjcrsfineoffdiag1d.o \
	fortran/FACjacobian3d.o \
	fortran/bcFluxCopy3d.o \
	fortran/bcFluxFix3d.o \
	fortran/bratufunc3d.o \
	fortran/err3d.o \
	fortran/evalBratu3d.o \
	fortran/evalDiffusionCoef3d.o \
	fortran/evalExponential3d.o \
	fortran/evalF3d.o \
	fortran/evalFaceFluxes3d.o \
	fortran/evalJv3d.o \
	fortran/evalSource3d.o \
	fortran/setbc3d.o \
	fortran/FACjacobian2d.o \
	fortran/bcFluxCopy2d.o \
	fortran/bcFluxFix2d.o \
	fortran/bratufunc2d.o \
	fortran/err2d.o \
	fortran/evalBratu2d.o \
	fortran/evalDiffusionCoef2d.o \
	fortran/evalExponential2d.o \
	fortran/evalF2d.o \
	fortran/evalFaceFluxes2d.o \
	fortran/evalJv2d.o \
	fortran/evalSource2d.o \
	fortran/setbc2d.o

main:	$(CXX_OBJS) $(F_OBJS) $(LIBSAMRAIDEPEND)
	for DIR in $(SUBDIRS); do if test -d $$DIR; then (cd $$DIR && $(MAKE) $@) ; fi || exit 1; done
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXX_OBJS) $(F_OBJS)	\
	$(LIBSAMRAI) $(LDLIBS) -o main

# Prevents "No rule to make target" error.  Built in the rule for main.
fortran/FACjacobian1d.o:

fortran/bcFluxCopy1d.o:

fortran/bcFluxFix1d.o:

fortran/bratufunc1d.o:

fortran/err1d.o:

fortran/evalBratu1d.o:

fortran/evalDiffusionCoef1d.o:

fortran/evalExponential1d.o:

fortran/evalF1d.o:

fortran/evalFaceFluxes1d.o:

fortran/evalJv1d.o:

fortran/evalSource1d.o:

fortran/setbc1d.o:

fortran/adjcrsfineoffdiag1d.o:

fortran/FACjacobian3d.o:

fortran/bcFluxCopy3d.o:

fortran/bcFluxFix3d.o:

fortran/bratufunc3d.o:

fortran/err3d.o:

fortran/evalBratu3d.o:

fortran/evalDiffusionCoef3d.o:

fortran/evalExponential3d.o:

fortran/evalF3d.o:

fortran/evalFaceFluxes3d.o:

fortran/evalJv3d.o:

fortran/evalSource3d.o:

fortran/setbc3d.o:

fortran/FACjacobian2d.o:

fortran/bcFluxCopy2d.o:

fortran/bcFluxFix2d.o:

fortran/bratufunc2d.o:

fortran/err2d.o:

fortran/evalBratu2d.o:

fortran/evalDiffusionCoef2d.o:

fortran/evalExponential2d.o:

fortran/evalF2d.o:

fortran/evalFaceFluxes2d.o:

fortran/evalJv2d.o:

fortran/evalSource2d.o:

fortran/setbc2d.o:

check:
	$(MAKE) check2d

check2d:	main
	@for i in test_inputs/*2d*.input ; do	\
	  for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	    echo "    <testcase classname=\"nonlinear\" name=$(QUOTE)$$i $$p procs$(QUOTE)>" >> $(REPORT); \
	    $(OBJECT)/config/serpa-run $$p ./main $${i} -skip_petscrc | $(TEE) foo; \
	    if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	    echo "    </testcase>" >> $(REPORT); \
	  done \
	done; \
	$(RM) foo

checkcompile: main

checktest:
	$(RM) makecheck.logfile
	$(MAKE) check 2>&1 | $(TEE) makecheck.logfile
	$(TESTTOOLS)/testcount.sh $(TEST_NPROCS) $(NUM_TESTS) 0 makecheck.logfile
	$(RM) makecheck.logfile

examples:

perf3d:	main
	@for i in performance_inputs/*3d*.input ; do	\
	  $(OBJECT)/config/serpa-run $(TEST_NPROCS) \
		./main $${i} -skip_petscrc;	\
	done

perf:
	$(MAKE) perf3d

everything:
	$(MAKE) checkcompile || exit 1
	$(MAKE) checktest
	$(MAKE) examples
	$(MAKE) perf

checkclean:
	$(CLEAN_COMMON_CHECK_FILES)
	$(RM) nkLog.32x32.8 *.timing*

clean: checkclean
	$(CLEAN_COMMON_TEST_FILES)
	$(RM) main
	for DIR in $(SUBDIRS); do if test -d $$DIR; then (cd $$DIR && $(MAKE) $@) ; fi || exit 1; done

include $(SRCDIR)/Makefile.depend


